package com.fastCms.manager.bim.controller;


import com.fastCms.business.bim.pojo.po.CategorySavePO;
import com.fastCms.business.bim.pojo.po.ChangeSortPO;
import com.fastCms.business.bim.pojo.po.ChangeStatusPO;
import com.fastCms.business.bim.pojo.po.ScenePO;
import com.fastCms.business.bim.pojo.vo.CategoryVO;
import com.fastCms.business.bim.service.CategoryService;
import com.fastCms.business.frame.exception.BusinessException;
import com.fastCms.business.frame.pojo.po.IdStrPO;
import com.fastCms.business.frame.response.ApiResponse;
import com.fastCms.business.frame.response.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 行业管理 前端控制器
 * </p>
 *
 * @author quan
 * @since 2024-05-23
 */
@Api(value = "CategoryController", tags = "类目分类统一管理")
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Resource
    private CategoryService categoryService;

    @PostMapping("/showList")
    @ApiOperation(value = "列表", notes = "不分页")
    public ApiResponse<List<CategoryVO>> showList(@RequestBody ScenePO param) {
        List<CategoryVO> result = categoryService.showList(param);
        return ResponseUtil.success(result);
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "新建或更新", notes = "如果增加在下一层级,需要传pid")
    public ApiResponse<Boolean> saveOrUpdate(@RequestBody CategorySavePO param) throws BusinessException {
        Boolean result = categoryService.saveOrUpdate(param);
        return ResponseUtil.success(result);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除", notes = "根据主键ID删除")
    public ApiResponse<Boolean> delete(@RequestBody IdStrPO param) throws BusinessException {
        ApiResponse<Boolean> result = categoryService.delete(param);
        return result;
    }

    @PostMapping("/changeStatus")
    @ApiOperation(value = "改变状态", notes = "1-展示 0-不展示")
    public ApiResponse<Boolean> changeStatus(@RequestBody ChangeStatusPO param) throws BusinessException {
        Boolean result = categoryService.changeStatus(param);
        return ResponseUtil.success(result);
    }

    @PostMapping("/changeSort")
    @ApiOperation(value = "改变", notes = "1-展示 0-不展示")
    public ApiResponse<Boolean> changeSort(@RequestBody List<ChangeSortPO> param) {
        Boolean result = categoryService.changeSort(param);
        return ResponseUtil.success(result);
    }

}

